<?php

/*
 * EachGo电商网站 新媒体
 * www.eachgo.cn
 */

namespace Home\Controller;

use Think\Controller;
use Think\Model;

class SchoolController extends Controller {

    public function querySchool() {
        // echo "lsdfj";
        $school = D('School');
        //$school=new Model('School');
        //$school=new \Model\SchoolModel();
        //$school = D('School', 'Home'); 
        $result = $school->queryAll();
        var_dump($result);
        //  $this->assign('result',$result);
        foreach ($result as $k => $v) {
            echo $v['id'] . "<br/>";
            echo $v['schoolname'] . "<br/>";
            echo $v['city'] . "<br/>";
            echo $v['province'] . "<br/>";
            echo $v['district'] . "<br/>";
        }
    }

    public function queryByName() {
        $school = D('School');
        $date = array('大', '望');
        $result = $school->queryLikeByName($date);
        var_dump($result);
    }
    public function queryById() {
        $school = D('School');
        $result = $school->queryById(32748);
        var_dump($result);
    }

    public function delSchool() {
        $school = D('School');
        $result = $school->deleteSchool(32751);
        echo $result;
    }

    public function updateSchool() {
        $school = D('School');
        $data = array(
            'ID' => 32748,
            'schoolName' => '成都大学龙泉校区',
            'city' => '成都市',
            'province' => '四川省',
            'district' => '龙泉驿区'
        );
        //echo __SELF__;
        $result = $school->update($data);
        var_dump($result);
        if ($result == 0) {
            echo "faile";
        } else {
            echo "success";
        }
    }

    public function addSchool() {
        $school = D('School');
        $date = array(
            'schoolName' => '西华大学',
            'city' => '成都市',
            'province' => '四川省',
            'district' => '金牛区'
        );
        $result = $school->addSchool($date);
        echo $result;
    }

}
